﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;

namespace BusinessLogic
{
    public class StoreProcedures
    {
        string cnstr = ConfigurationManager.ConnectionStrings["QLNTConStr"].ToString();
        public void UpdateUser(int UserID, string email, string fullName, int gender, string birthday, string memberType,
            string phoneNo, string address)
        {

            SqlConnection con = new SqlConnection(cnstr);
            SqlCommand cmd = new SqlCommand("proUpdateUsers", con);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@UserID", SqlDbType.Int).Value = UserID;
            cmd.Parameters.Add("@strEmail", SqlDbType.VarChar).Value = email;
            cmd.Parameters.Add("@strFullname", SqlDbType.NVarChar).Value = fullName;
            cmd.Parameters.Add("@intGender", SqlDbType.Bit).Value = gender;
            cmd.Parameters.Add("@dtBirthday", SqlDbType.DateTime).Value = birthday;
            cmd.Parameters.Add("@strMemberType", SqlDbType.NVarChar).Value = memberType;
            cmd.Parameters.Add("@strPhoneNo", SqlDbType.VarChar).Value = phoneNo;
            cmd.Parameters.Add("@strAddress", SqlDbType.NVarChar).Value = address;

            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();

        }

        public void insertUser(string userName, string pass, string email, string fullName, int gender, string birthday, string memberType,
           string phoneNo, string address, string question, string answer)
        {

            SqlConnection con = new SqlConnection(cnstr);
            SqlCommand cmd = new SqlCommand("proInsertUsers", con);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@strUserName", SqlDbType.VarChar).Value = userName;
            cmd.Parameters.Add("@strPass", SqlDbType.VarChar).Value = pass;
            cmd.Parameters.Add("@strEmail", SqlDbType.VarChar).Value = email;
            cmd.Parameters.Add("@strFullname", SqlDbType.NVarChar).Value = fullName;
            cmd.Parameters.Add("@intGender", SqlDbType.Bit).Value = gender;
            cmd.Parameters.Add("@dtBirthday", SqlDbType.DateTime).Value = birthday;
            cmd.Parameters.Add("@strMemberType", SqlDbType.NVarChar).Value = memberType;
            cmd.Parameters.Add("@strPhoneNo", SqlDbType.VarChar).Value = phoneNo;
            cmd.Parameters.Add("@strAddress", SqlDbType.NVarChar).Value = address;
            cmd.Parameters.Add("@strQuestion", SqlDbType.NVarChar).Value = question;
            cmd.Parameters.Add("@strAnswer", SqlDbType.NVarChar).Value = answer;

            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();

        }

    }
}
